<html>
<head><meta charset="utf-8"><title>Structuring name resolutino · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structuring.20name.20resolutino.html">Structuring name resolutino</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="183946211"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structuring%20name%20resolutino/near/183946211" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structuring.20name.20resolutino.html#183946211">(Dec 20 2019 at 15:41)</a>:</h4>
<p>I've been doing various refactorings around our name res and noticed that handling of globs and legacy macros works rougthly like this:</p>
<div class="codehilite"><pre><span></span><span class="k">for</span><span class="w"> </span><span class="n">module</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">modules</span><span class="p">.</span><span class="n">iter</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">modules</span><span class="p">.</span><span class="n">get_mut</span><span class="p">(</span><span class="n">some_other_module</span><span class="p">).</span><span class="n">import_from</span><span class="p">(</span><span class="n">module</span><span class="p">)</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<p>That is, when doing fixed-point shenanigans we simultaneously iterate and mutate scopes. This obviously doesn't work out due to this annoying borrow checker, so we insert a bunch of clones in various places. I wonder if that's a sign that we need some more explicit work-list style approach.</p>
<p>Basically, we split each iteration into two parts:</p>
<div class="codehilite"><pre><span></span>fn compute_diff(&amp;self) -&gt; Diff;
fn apply_diff(&amp;mut self, diff: Diff);
</pre></div>


<p>That way, we solve the ailasing problem, and maybe also make the code clearer, as iterations become indipendent of each other.</p>
<p>Granted, the <code>Diff</code> thing would probably be isomorphic to the cloning we do today, but it will be an explicit struct one can <code>eprintln!("{:?}")</code>, instead of a number of local <code>.clone</code>s all other the place</p>



<a name="183946742"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structuring%20name%20resolutino/near/183946742" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structuring.20name.20resolutino.html#183946742">(Dec 20 2019 at 15:47)</a>:</h4>
<p>sounds like a good idea to me</p>



<a name="183947454"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structuring%20name%20resolutino/near/183947454" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structuring.20name.20resolutino.html#183947454">(Dec 20 2019 at 15:54)</a>:</h4>
<p>I always like 'reifying' things ;)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>